home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / 3DVIS10.ZIP / SOURCE3.C < prev    next >
Text File  |  1996-02-29  |  2KB  |  74 lines

  1. /*** SOURCE3.C - Creates a .3DV file with the definition of 2 curves
  2.          by Lenimar N. Andrade, ccendm03@brufpb.bitnet
  3.       Dep. of Mathematics - Universidade Federal da Paraíba - Brazil ***/
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <conio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10.  
  11. unsigned nu = 500;
  12. FILE *arq;
  13.  
  14. /* Parametric equations of the curves */
  15. float f1(float t) { return 2*sin(2*t); }
  16. float f2(float t) { return 2*sin(t)*cos(2*t); }
  17. float f3(float t) { return 2*cos(t)*cos(2*t); }
  18.  
  19. float g1(float t) { return 1.5*sin(2*t); }
  20. float g2(float t) { return 1.5*sin(t)*cos(2*t); }
  21. float g3(float t) { return 1.5*cos(t)*cos(2*t); }
  22.  
  23. /* ------------------------------------------------------------------------- */
  24.  
  25. void CalcPoints2(float umin, float umax) {
  26.  
  27.   float u, incrU;
  28.   unsigned i;
  29.  
  30.   incrU = (umax - umin)/nu;
  31.  
  32.   fprintf(arq, "%u\n", 2*(nu + 1));
  33.   for (u = umin; u < umax + incrU/2; u+= incrU)
  34.     fprintf(arq, "%6.3f %6.3f %6.3f\n", f1(u), f2(u), f3(u));
  35.   for (u = umin; u < umax + incrU/2; u+= incrU)
  36.     fprintf(arq, "%6.3f %6.3f %6.3f\n", g1(u), g2(u), g3(u));
  37.  
  38.   fprintf(arq, "%u\n", 2*(nu + 1));
  39.   for (i = 1; i <= nu + 1; i++) {
  40.     fprintf(arq, "%u %u\n", i, 0);
  41.     fprintf(arq, "%u %u\n", i + nu + 1, 1 + random(15));
  42.   }
  43. }
  44.  
  45. /* ------------------------------------------------------------------------- */
  46.  
  47. void PrintMsg(void) {
  48.  
  49.   fprintf(arq, "\n%s", "Segments linking f(t) = (2*sin(2*t), "
  50.                    "2*sin(t)*cos(2*t), 2*cos(t)*cos(2*t))");
  51.   fprintf(arq, "\n%s", "             and g(t) = (1.5*sin(2*t),"
  52.                    "1.5*sin(t)*cos(2*t),1.5*cos(t)*cos(2*t))");
  53.   fprintf(arq, "\n%s", "Lenimar Nunes de Andrade, ccendm03@brufpb.bitnet\n");
  54. }
  55.  
  56. /* ------------------------------------------------------------------------- */
  57.  
  58. void main(void) {
  59.  
  60.   time_t x;
  61.  
  62.   srand((unsigned) time(&x));
  63.   randomize();
  64.  
  65.   if ((arq = fopen("demo3.3dv", "wt")) == NULL) return;
  66.   CalcPoints2(0, 6.2832);
  67.   PrintMsg();
  68.   fclose(arq);
  69. }
  70.  
  71. /* ------------------------------------------------------------------------- */
  72.  
  73. /*** END OF "SOURCE3.C" ***/
  74.